//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by huxuedong on 15/12/5.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

import UIKit

//item字体大小
let itemTitleFontSize: CGFloat = 15
//item字体颜色
let itemTitleColor: UIColor = UIColor(white: 80 / 255, alpha: 1)

extension UIBarButtonItem {
    //便利构造方法
    convenience init(imageName: String? = nil, title: String? = nil, target: AnyObject?, action: Selector) {
        self.init()
        let button = UIButton()
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        if let imageName = imageName {
            button.setImage(UIImage(named: imageName), forState: .Normal)
            button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: .Highlighted)
        }
        if let title = title {
            button.setTitle(title, forState: .Normal)
            button.setTitleColor(itemTitleColor, forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.titleLabel?.font = UIFont.systemFontOfSize(itemTitleFontSize)
        }
        button.sizeToFit()
        customView = button
    }
}
